package cn.edu.hnu.homework.api.Model;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

@Setter
@Getter
@ToString
public class ResponseBean implements Serializable {

    /**
     * 状态:1-成功,0-失败
     */
    private Integer status;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * json业务信息
     */
    private Object data;

    private String name;
    private int age;
    private String phone;
    private String username;

    /**
     * 重定向URL，处理失败需要跳转时使用
     */
    private String redirectUrl;

    public ResponseBean(boolean success) {
        this.status = (success == true) ? 1 : 0;
    }

    public ResponseBean(boolean success, Object data) {
        this.status = (success == true) ? 1 : 0;
        this.data = data;
    }

    /**
     * 构造函数
     * <pre>需要页面重定向时使用</pre>
     *
     * @param success     是否成功
     * @param redirectUrl 跳转URL
     */
    public ResponseBean(boolean success, String redirectUrl) {
        this.status = (success == true) ? 1 : 0;
        this.redirectUrl = redirectUrl;
    }

    public ResponseBean(boolean success, String msg, Object data) {
        this.status = (success == true) ? 1 : 0;
        this.msg = msg;
        this.data = data;
    }

}
